package com.jzoffer;

/*
* 因为n级台阶，第一步有n种跳法：跳1级、跳2级、到跳n级
跳1级，剩下n-1级，则剩下跳法是f(n-1)
跳2级，剩下n-2级，则剩下跳法是f(n-2)
所以f(n)=f(n-1)+f(n-2)+...+f(1)
因为f(n-1)=f(n-2)+f(n-3)+...+f(1)
所以f(n)=2*f(n-1)
*
* */
public class JumpFloorPlus {
    public static void main(String[] args) {
        int n = 5;
        System.out.println(JumpFloorII(n));


    }

    public static int JumpFloorII(int target){
        if(target < 2){
            return target;
        }
        int[] dp = new int[target + 1];
        dp[0] = 0;
        dp[1] = 1;
        for(int i = 2;i <= target;i++){
            dp[i] = 2 * dp[i -1];
        }
        return dp[target];
    }
}
